class Solution {
public:
    ListNode* TogetherTwoLists(ListNode* l1, ListNode* l2) {
        ListNode* p = new ListNode(0);
        ListNode* temp = p; //新链表
        while( l1 || l2 ){
            //如果一者为空就把剩下链表的连接到新链表的尾部
            if(l1==NULL){
                p->next = l2;
                break;
            }else if(l2==NULL){
                p->next = l1;
                break;
            }else{
                if ( l1->val < l2->val ){
                    p->next = l1;
                    l1 = l1->next;
                }else{
                    p->next = l2;
                    l2 = l2->next;
                }
                p=p->next;
            }
        }
        return temp->next;
    }
};